package com.qiang.androidinfo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

import com.qiang.androidinfo.Manager.MobileInfoManger;

import cn.bmob.v3.Bmob;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView tvInfo = (TextView) findViewById(R.id.tv_info);
        MobileInfoManger mMobileInfo = MobileInfoManger.getInstance();

        tvInfo.setText(mMobileInfo.getInfo());

        initBmob();
        initMobileInfo();
    }

    private void initMobileInfo() {
        MobileInfoManger mMobileInfo = MobileInfoManger.getInstance();
        MobilePhoneInfo phoneInfo = new MobilePhoneInfo();

        phoneInfo.imei =mMobileInfo.getIMEI();

        phoneInfo.buildModel=mMobileInfo.getBuildModel();
        phoneInfo.buildManufacturer=mMobileInfo.getManUfacturer();
        phoneInfo.buildHardware=mMobileInfo.getHardWare();
        phoneInfo.buildBrand=mMobileInfo.getBrand();
        phoneInfo.buildBoard=mMobileInfo.getBoard();
        phoneInfo.buildProduct=mMobileInfo.getProduct();
        phoneInfo.buildRelease=mMobileInfo.getRelease();
        phoneInfo.buildSdkInt=mMobileInfo.getSdkInt();
        phoneInfo.buildBootLoader=mMobileInfo.getBootLoader();
        phoneInfo.buildCPU=mMobileInfo.getCPU();
        phoneInfo.buildCPU2=mMobileInfo.getCPU2();
        phoneInfo.buildCPU2=mMobileInfo.getCPU2();
        phoneInfo.buildDevice=mMobileInfo.getDevice();
        phoneInfo.buildFingerPrint=mMobileInfo.getFingerPrint();
        phoneInfo.buildIncremental=mMobileInfo.getBuildIncremental();
        phoneInfo.buildRadio=mMobileInfo.getRadioVersion();
        phoneInfo.buildID=mMobileInfo.getBuildId();
        phoneInfo.buildTags=mMobileInfo.getBuildTags();
        phoneInfo.buildType=mMobileInfo.getBuildType();
        phoneInfo.buildUser=mMobileInfo.getBuildUser();
        phoneInfo.buildDisplay=mMobileInfo.getDisplay();
        phoneInfo.displayDPI=mMobileInfo.getDisplayDPI();
        phoneInfo.displayHeight=mMobileInfo.getDisplayHeightP();
        phoneInfo.displayWidth=mMobileInfo.getDisplayWidthP();


        phoneInfo.save(new SaveListener<String>() {
            @Override
            public void done(String objectId,BmobException e) {
                if(e==null){
                    Toast.makeText(MainActivity.this, "添加数据成功", Toast.LENGTH_SHORT).show();
                }else{
                    Toast.makeText(MainActivity.this, "创建数据失败"+e.getMessage(), Toast.LENGTH_LONG).show();
                }
            }
        });



    }

    private void initBmob() {

        Bmob.initialize(this, "93adb30d37cf715d8e7961a10480d517");
    }
}
